/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JFreeChartExtensions.utils;

import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JViewport;

/**
 *
 * @author Nobody
 */
public class Helper {

    private static Helper helper;
  
  
    public static Helper getHelper() {
        if (helper == null) {
            helper = new Helper();
        }
        return helper;
    }

    public void changePanelState(Component parent, boolean state) {
        if (state) {
            enablePanel(parent);
        } else {
            disablePanel(parent);
        }
    }

    public void disablePanel(Component parent) {
        Component[] com = null;
        if (parent instanceof JPanel) {
            com = ((JPanel) parent).getComponents();
        } else if (parent instanceof JScrollPane) {
            com = ((JScrollPane) parent).getComponents();
        } else if (parent instanceof JViewport) {
            com = ((JViewport) parent).getComponents();
        } else {
            return;
        }
        for (int a = 0; a < com.length; a++) {
            com[a].setEnabled(false);
            disablePanel(com[a]);
        }

    }

    public void enablePanel(Component parent) {
        Component[] com = null;
        if (parent instanceof JPanel) {
            com = ((JPanel) parent).getComponents();
        } else if (parent instanceof JScrollPane) {
            com = ((JScrollPane) parent).getComponents();
        } else if (parent instanceof JViewport) {
            com = ((JViewport) parent).getComponents();
        } else {
            return;
        }

        for (int a = 0; a < com.length; a++) {
            com[a].setEnabled(true);
            enablePanel(com[a]);
        }
    }

}
